
capture log close
log using $log/EDS_16_variation_border_pairs, text replace

clear
clear matrix
clear mata
set mem 2g
set matsize 800
set more off
set maxvar 20000
set trace off
set varabbrev off


	 use $data/data_pair, clear
	 
	 bys region region_pair year: keep if _n==1
	 encode region_pair, g(region_pair2)
	 
	 sort region_pair2 year region
	 by region_pair2 year: gen group = _n
	 
	 keep region_pair2 year log_intensity_alt group
	 
	 egen year_pair = group(year region_pair2)
	 reshape wide log_intensity_alt, i(year_pair) j(group)
	 
	 gen diff_intensity = log_intensity_alt2 - log_intensity_alt1
	 
	 keep diff_intensity region_pair2 year 
	 reshape wide diff_intensity, i(region_pair2) j(year)
	 
	 gen did = diff_intensity2008 - diff_intensity2007
	 
	 gen did_abs = abs(did)
	 replace did_abs=1 if did_abs>1
	 
	 
	 cumul did_abs,gen(did_cum) 
	 sort did_abs
	 
	 #d;
	 twoway (line did_cum did_abs), scheme(s2mono)
	 graphregion(color(white)) legend(off)  ytitle("Fraction of border pairs")
	 xscale(r(0 1)) xlabel(0 "0" 0.1 "0.1" 0.3 "0.3" 0.5 "0.5" 0.7 "0.7" 0.9 "0.9")  
	 yscale(r(0 1)) ylabel(0(0.2)1)
	 xtitle("Log treatment intensity difference-in-differences (abs.)")
	 xline(0.25, lpattern(dash_dot)) text(0.99 0.45 "Changes in treatment intensity", size(small)) text(0.95 0.45 "differences of at least 25%", size(small));
	 #d cr
	 graph export $data/Figure_A3.png, as(png) replace
	  
	 log close
	 
	

